package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.query.DestinationQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.util.JsonResult;
import cn.wolfcode.wolf2w.util.MsgJsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("destination")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;

    /**
     * 目的地列表/分页查询
     */
    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") DestinationQuery qo){

        model.addAttribute("page",destinationService.query(qo));

        model.addAttribute("toasts",destinationService.queryToasts(qo.getParentId()));

        return "destination/list";
    }

    /**
     * 编辑目的地简介
     * @param id
     * @param info
     * @return
     */
    @RequestMapping("updateInfo")
    @ResponseBody
    public Object updateInfo(String id,String info){
        destinationService.updateInfo(id,info);
        return new MsgJsonResult();
    }

    /**
     * 删除目的地
     */
    @RequestMapping("delete")
    @ResponseBody
    public Object delete(String id){
        destinationService.delete(id);
        return JsonResult.success();
    }



}
